//% color="#8A2BE2" iconWidth=50 iconHeight=40
namespace DFRobot_SerialScreen771{
    //% board="esp32,microbit,arduino,arduinonano,mega2560,leonardo"
    //% block="DFRobot_SerialScreen771 init HardSerial [HS]RX [RX]TX [TX] " blockType="command" 
    //% HS.shadow="dropdown"  HS.options="HS"
    //% RX.shadow="dropdown"  RX.options="RX"
    //% TX.shadow="dropdown"  TX.options="TX"
    export function DFRobot_SerialScreen7713InitSerial(parameter: any, block: any) {
        let hs=parameter.HS.code;
        let rx=parameter.RX.code;
        let tx=parameter.TX.code;

       
        Generator .addInclude("DFRobot_SerialScreen771Init3", "#include <DFRobot_SerialScreen771.h>");
        Generator.addObject("DFRobot_SerialScreen7713","DFRobot_SerialScreen771","screen;");

      

        if(Generator.board === 'esp32'){
            Generator.addSetup(`DFRobot_SerialScreen771Init2`,`screen.begin(&${hs},${rx},${tx});`);
        }else if(Generator.board === 'microbit') { 
            Generator.addSetup(`DFRobot_SerialScreen771Init2`,`screen.begin(&Serial,${rx},${tx});`);
        }else if(Generator.board === 'arduino') {
            Generator.addInclude("DFRobot_SerialScreen771Init", "#include <Arduino.h>");
            Generator.addSetup(`DFRobot_SerialScreen771Init2`,`screen.begin(&Serial,${rx},${tx});`);
        }else if(Generator.board === 'arduinonano') {
            Generator.addInclude("DFRobot_SerialScreen771Init", "#include <Arduino.h>");
            Generator.addSetup(`DFRobot_SerialScreen771Init2`,`screen.begin(&Serial,${rx},${tx});`);
        }else if(Generator.board === 'mega2560') {
            Generator.addInclude("DFRobot_SerialScreen771Init", "#include <Arduino.h>");
            Generator.addSetup(`DFRobot_SerialScreen771Init2`,`screen.begin(&Serial,${rx},${tx});`);
        }
        else if(Generator.board === 'leonardo') {
            Generator.addInclude("DFRobot_SerialScreen771Init", "#include <Arduino.h>");
            Generator.addSetup(`DFRobot_SerialScreen771Init2`,`screen.begin(&Serial1,${rx},${tx});`);
        }
}
    //% block="DFRobot_SerialScreen771 init SoftSeril[SS]RX [SRX]TX [STX] " blockType="command"
    //% SS.shadow="dropdown"   SS.options="SS"
    //% SRX.shadow="dropdown"  SRX.options="SRX"
    //% STX.shadow="dropdown"  STX.options="STX"
    export function DFRobot_SerialScreen7713Init(parameter: any, block: any) {
        let ss=parameter.SS.code;
        let r=parameter.SRX.code;
        let w=parameter.STX.code;

     
         
       

        if(Generator.board === 'arduino') {
            Generator.addInclude("DFRobot_SerialScreen771Init", "#include <Arduino.h>");
        }else if(Generator.board === 'arduinonano') {
            Generator.addInclude("DFRobot_SerialScreen771Init", "#include <Arduino.h>");
        }else if(Generator.board === 'leonardo') {
            Generator.addInclude("DFRobot_SerialScreen771Init", "#include <Arduino.h>");
        }else if(Generator.board === 'mega2560') {
            Generator.addInclude("DFRobot_SerialScreen771Init", "#include <Arduino.h>");
        }
       
        Generator.addInclude("DFRobot_SerialScreen771Init2", "#include <SoftwareSerial.h>");
        Generator.addInclude("DFRobot_SerialScreen771Init3", "#include <DFRobot_SerialScreen771.h>");
        Generator.addObject("DFRobot_SerialScreen7711","SoftwareSerial",`${ss}(${r}, ${w});`);
        Generator.addObject("DFRobot_SerialScreen7713","DFRobot_SerialScreen771","screen;");
        Generator.addSetup(`DFRobot_SerialScreen771Init2`,`screen.begin(&${ss});`);
}


//% block="DFRobot_SerialScreen771  Setprint Mode [MODE]Spedd [SPEED]Level [LEVEL]" blockType="command"
//% MODE.shadow="dropdown"  MODE.options="MODE"
//% SPEED.shadow="dropdown"  SPEED.options="SPEED"
//% LEVEL.shadow="dropdown"  LEVEL.options="LEVEL"
 export function DFRobot_SerialScreen7713mode(parameter: any, block: any) {
    let mode=parameter.MODE.code;
    let speed=parameter.SPEED.code;
    let level=parameter.LEVEL.code;
console.log(parameter.SPEED.parType );
    Generator.addCode(`screen.setMoveMode(${mode});`);
    Generator.addCode(`screen.setMoveSpeed(${speed});`);
    Generator.addCode(`screen.setBrightness(${level});`);
}

//% block="DFRobot_SerialScreen771 Color [COLOR]" blockType="command"
//% COLOR.shadow="dropdown"  COLOR.options="COLOR"
export function DFRobot_SerialScreen7713colorall(parameter: any, block: any) {
    let color = parameter.COLOR.code;
    Generator.addCode(`screen.setFullScreenColor(${color});`);
    
} 

//% block="DFRobot_SerialScreen771 setprint Mess [MESS]   " blockType="command"
//% MESS.shadow="string"  MESS.defl="DFRobot"
export function DFRobot_SerialScreen7713setMessage1(parameter: any, block: any) {
    let mess=parameter.MESS.code;
    

// 如果 mess 包含任何类型的引号，你可能需要对其进行转义
if (mess.charAt(0) === '"') {
    // 转义引号，确保字符串能够正确地被使用
    
    Generator.addCode(`screen.setMessage(${mess});`);
  
}else{
    Generator.addCode(`screen.setMessage(${mess}.c_str());`);
    
}  
}


//% block="DFRobot_SerialScreen771 Setprint Mess [MESS]Font Color[FONT]Background Color[BG] " blockType="command"
//% MESS.shadow="string"  MESS.defl="DFRobot"
//% FONT.shadow="dropdown"  FONT.options="FONT"
//% BG.shadow="dropdown"  BG.options="BG"
export function DFRobot_SerialScreen7713setMessage(parameter: any, block: any) {
    let mess=parameter.MESS.code;
    let font=parameter.FONT.code;
    let bg=parameter.BG.code;

    
 
// 如果 mess 包含任何类型的引号，你可能需要对其进行转义
if (mess.charAt(0) === '"') {
    // 转义引号，确保字符串能够正确地被使用
    Generator.addCode(`screen.setMessage(${mess});`);
    Generator.addCode(`screen.setDispalyColor(${font}, ${bg});`);
}else{
    Generator.addCode(`screen.setMessage(${mess}.c_str());`);
    Generator.addCode(`screen.setDispalyColor(${font}, ${bg});`);
}
}

//% block="DFRobot_SerialScreen771setMessageList PrintList[NU]Mess [MESS]Font Color[FONT]Background Color[BG]" blockType="command"
//% NU.shadow="number"  NU.defl="1"
//% MESS.shadow="string"  MESS.defl="DFRobot"
//% FONT.shadow="dropdown"  FONT.options="FONT"
//% BG.shadow="dropdown"  BG.options="BG"
export function DFRobot_SerialScreen7713setMessageList(parameter: any, block: any) {
    let nu=parameter.NU.code;
    let mess=parameter.MESS.code;
    let font=parameter.FONT.code;
    let bg=parameter.BG.code;
    
    Generator.addCode(`screen.setMessageList(${nu}, ${mess});`);
    Generator.addCode(`screen.setDispalyColor(${font}, ${bg});`);
    
}
//% block="DFRobot_SerialScreen771setMessageList Print[LIST]" blockType="command"
//% LIST.shadow="dropdown"  LIST.options="LIST"
 
export function DFRobot_SerialScreen7713setMessageListprint(parameter: any, block: any) {
    let list=parameter.LIST.code;
    
    
    Generator.addCode(`screen.displayBanner("${list}");`);
    
}


}